
/****** Object:  Stored Procedure dbo.spi_InPanel_Delete    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spi_InPanel_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spi_InPanel_Delete]
GO

/****** Object:  Stored Procedure dbo.spi_InPanel_GetById    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spi_InPanel_GetById]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spi_InPanel_GetById]
GO

/****** Object:  Stored Procedure dbo.spi_InPanel_GetList    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spi_InPanel_GetList]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spi_InPanel_GetList]
GO

/****** Object:  Stored Procedure dbo.spi_InPanel_GetByPaging    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spi_InPanel_GetByPaging]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spi_InPanel_GetByPaging]
GO

/****** Object:  Stored Procedure dbo.spi_InPanel_Insert    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spi_InPanel_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spi_InPanel_Insert]
GO

/****** Object:  Stored Procedure dbo.spi_InPanel_Update    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spi_InPanel_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spi_InPanel_Update]
GO



SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Delete InPanel by PanelId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spi_InPanel_Delete
	@PanelId int
AS

DELETE FROM [InPanel]
WHERE
	[PanelId] = @PanelId
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get InPanel by PanelId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spi_InPanel_GetById
	@PanelId int
AS

SELECT
	[PanelId]
	, [PanelParentId]
	, [PanelName]
	, [PanelSatus]
FROM
	[InPanel]
WHERE
	[PanelId] = @PanelId

GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get all from InPanel
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spi_InPanel_GetList
AS

SELECT
	[PanelId]
	, [PanelParentId]
	, [PanelName]
	, [PanelSatus]
FROM
	[InPanel]

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get InPanel by paging
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[spi_InPanel_GetByPaging]
@PageIndex INT,
@PageSize INT,
@TotalRecord INT OUTPUT
AS
	SELECT @TotalRecord = COUNT(*) FROM [InPanel]
	DECLARE @StartRow INT
	SET @StartRow = (@PageIndex - 1) * @PageSize + 1
	DECLARE @EndRow INT
	SET @EndRow = @PageIndex * @PageSize
SELECT * FROM
(
	SELECT TOP(@EndRow)
	[PanelId]
	, [PanelParentId]
	, [PanelName]
	, [PanelSatus]
	, ROW_NUMBER() OVER(ORDER BY PanelId ASC) RowIndex
FROM
	[InPanel]
) indexTable
WHERE RowIndex BETWEEN @StartRow AND @EndRow
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Insert into InPanel
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spi_InPanel_Insert
	@PanelParentId int, 
	@PanelName nvarchar(50), 
	@PanelSatus int, 
	@PanelId int OUTPUT
AS
BEGIN

INSERT INTO [InPanel] (
	[PanelParentId]
	, [PanelName]
	, [PanelSatus]
) VALUES (
	@PanelParentId
	, @PanelName
	, @PanelSatus
)

SET @PanelId = @@IDENTITY

END


GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Update from InPanel by PanelId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spi_InPanel_Update
	
	@PanelId int 
	, @PanelParentId int 
	, @PanelName nvarchar(50) 
	, @PanelSatus int 
AS

UPDATE [InPanel] SET
	[PanelParentId] = @PanelParentId
	, [PanelName] = @PanelName
	, [PanelSatus] = @PanelSatus
WHERE
	[PanelId] = @PanelId

GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
/****** Object:  Stored Procedure dbo.spi_InPms_Delete    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spi_InPms_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spi_InPms_Delete]
GO

/****** Object:  Stored Procedure dbo.spi_InPms_GetById    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spi_InPms_GetById]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spi_InPms_GetById]
GO

/****** Object:  Stored Procedure dbo.spi_InPms_GetList    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spi_InPms_GetList]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spi_InPms_GetList]
GO

/****** Object:  Stored Procedure dbo.spi_InPms_GetByPaging    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spi_InPms_GetByPaging]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spi_InPms_GetByPaging]
GO

/****** Object:  Stored Procedure dbo.spi_InPms_Insert    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spi_InPms_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spi_InPms_Insert]
GO

/****** Object:  Stored Procedure dbo.spi_InPms_Update    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spi_InPms_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spi_InPms_Update]
GO



SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Delete InPms by PmsId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spi_InPms_Delete
	@PmsId int
AS

DELETE FROM [InPms]
WHERE
	[PmsId] = @PmsId
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get InPms by PmsId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spi_InPms_GetById
	@PmsId int
AS

SELECT
	[PmsId]
	, [GroupId]
	, [PanelId]
	, [PmsView]
	, [PmsUpdate]
	, [PmsDelete]
FROM
	[InPms]
WHERE
	[PmsId] = @PmsId

GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get all from InPms
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spi_InPms_GetList
AS

SELECT
	[PmsId]
	, [GroupId]
	, [PanelId]
	, [PmsView]
	, [PmsUpdate]
	, [PmsDelete]
FROM
	[InPms]

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get InPms by paging
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[spi_InPms_GetByPaging]
@PageIndex INT,
@PageSize INT,
@TotalRecord INT OUTPUT
AS
	SELECT @TotalRecord = COUNT(*) FROM [InPms]
	DECLARE @StartRow INT
	SET @StartRow = (@PageIndex - 1) * @PageSize + 1
	DECLARE @EndRow INT
	SET @EndRow = @PageIndex * @PageSize
SELECT * FROM
(
	SELECT TOP(@EndRow)
	[PmsId]
	, [GroupId]
	, [PanelId]
	, [PmsView]
	, [PmsUpdate]
	, [PmsDelete]
	, ROW_NUMBER() OVER(ORDER BY PmsId ASC) RowIndex
FROM
	[InPms]
) indexTable
WHERE RowIndex BETWEEN @StartRow AND @EndRow
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Insert into InPms
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spi_InPms_Insert
	@GroupId int, 
	@PanelId int, 
	@PmsView tinyint, 
	@PmsUpdate tinyint, 
	@PmsDelete tinyint, 
	@PmsId int OUTPUT
AS
BEGIN

INSERT INTO [InPms] (
	[GroupId]
	, [PanelId]
	, [PmsView]
	, [PmsUpdate]
	, [PmsDelete]
) VALUES (
	@GroupId
	, @PanelId
	, @PmsView
	, @PmsUpdate
	, @PmsDelete
)

SET @PmsId = @@IDENTITY

END


GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Update from InPms by PmsId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spi_InPms_Update
	
	@PmsId int 
	, @GroupId int 
	, @PanelId int 
	, @PmsView tinyint 
	, @PmsUpdate tinyint 
	, @PmsDelete tinyint 
AS

UPDATE [InPms] SET
	[GroupId] = @GroupId
	, [PanelId] = @PanelId
	, [PmsView] = @PmsView
	, [PmsUpdate] = @PmsUpdate
	, [PmsDelete] = @PmsDelete
WHERE
	[PmsId] = @PmsId

GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
/****** Object:  Stored Procedure dbo.spi_InUser_Delete    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spi_InUser_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spi_InUser_Delete]
GO

/****** Object:  Stored Procedure dbo.spi_InUser_GetById    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spi_InUser_GetById]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spi_InUser_GetById]
GO

/****** Object:  Stored Procedure dbo.spi_InUser_GetList    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spi_InUser_GetList]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spi_InUser_GetList]
GO

/****** Object:  Stored Procedure dbo.spi_InUser_GetByPaging    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spi_InUser_GetByPaging]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spi_InUser_GetByPaging]
GO

/****** Object:  Stored Procedure dbo.spi_InUser_Insert    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spi_InUser_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spi_InUser_Insert]
GO

/****** Object:  Stored Procedure dbo.spi_InUser_Update    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spi_InUser_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spi_InUser_Update]
GO



SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Delete InUser by UserId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spi_InUser_Delete
	@UserId int
AS

DELETE FROM [InUser]
WHERE
	[UserId] = @UserId
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get InUser by UserId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spi_InUser_GetById
	@UserId int
AS

SELECT
	[UserId]
	, [GroupId]
	, [UserName]
	, [UserPass]
	, [UserMail]
	, [UserPhone]
	, [UserFullname]
	, [UserBirthday]
	, [UserAvatar]
	, [UserIdentity]
	, [UserStatus]
FROM
	[InUser]
WHERE
	[UserId] = @UserId

GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get all from InUser
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spi_InUser_GetList
AS

SELECT
	[UserId]
	, [GroupId]
	, [UserName]
	, [UserPass]
	, [UserMail]
	, [UserPhone]
	, [UserFullname]
	, [UserBirthday]
	, [UserAvatar]
	, [UserIdentity]
	, [UserStatus]
FROM
	[InUser]

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get InUser by paging
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[spi_InUser_GetByPaging]
@PageIndex INT,
@PageSize INT,
@TotalRecord INT OUTPUT
AS
	SELECT @TotalRecord = COUNT(*) FROM [InUser]
	DECLARE @StartRow INT
	SET @StartRow = (@PageIndex - 1) * @PageSize + 1
	DECLARE @EndRow INT
	SET @EndRow = @PageIndex * @PageSize
SELECT * FROM
(
	SELECT TOP(@EndRow)
	[UserId]
	, [GroupId]
	, [UserName]
	, [UserPass]
	, [UserMail]
	, [UserPhone]
	, [UserFullname]
	, [UserBirthday]
	, [UserAvatar]
	, [UserIdentity]
	, [UserStatus]
	, ROW_NUMBER() OVER(ORDER BY UserId ASC) RowIndex
FROM
	[InUser]
) indexTable
WHERE RowIndex BETWEEN @StartRow AND @EndRow
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Insert into InUser
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spi_InUser_Insert
	@GroupId int, 
	@UserName nvarchar(30), 
	@UserPass nvarchar(50), 
	@UserMail nvarchar(50), 
	@UserPhone nvarchar(20), 
	@UserFullname nvarchar(50), 
	@UserBirthday datetime, 
	@UserAvatar nvarchar(200), 
	@UserIdentity nvarchar(20), 
	@UserStatus int, 
	@UserId int OUTPUT
AS
BEGIN

INSERT INTO [InUser] (
	[GroupId]
	, [UserName]
	, [UserPass]
	, [UserMail]
	, [UserPhone]
	, [UserFullname]
	, [UserBirthday]
	, [UserAvatar]
	, [UserIdentity]
	, [UserStatus]
) VALUES (
	@GroupId
	, @UserName
	, @UserPass
	, @UserMail
	, @UserPhone
	, @UserFullname
	, @UserBirthday
	, @UserAvatar
	, @UserIdentity
	, @UserStatus
)

SET @UserId = @@IDENTITY

END


GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Update from InUser by UserId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spi_InUser_Update
	
	@UserId int 
	, @GroupId int 
	, @UserName nvarchar(30) 
	, @UserPass nvarchar(50) 
	, @UserMail nvarchar(50) 
	, @UserPhone nvarchar(20) 
	, @UserFullname nvarchar(50) 
	, @UserBirthday datetime 
	, @UserAvatar nvarchar(200) 
	, @UserIdentity nvarchar(20) 
	, @UserStatus int 
AS

UPDATE [InUser] SET
	[GroupId] = @GroupId
	, [UserName] = @UserName
	, [UserPass] = @UserPass
	, [UserMail] = @UserMail
	, [UserPhone] = @UserPhone
	, [UserFullname] = @UserFullname
	, [UserBirthday] = @UserBirthday
	, [UserAvatar] = @UserAvatar
	, [UserIdentity] = @UserIdentity
	, [UserStatus] = @UserStatus
WHERE
	[UserId] = @UserId

GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
/****** Object:  Stored Procedure dbo.spo_OutBill_Delete    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutBill_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutBill_Delete]
GO

/****** Object:  Stored Procedure dbo.spo_OutBill_GetById    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutBill_GetById]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutBill_GetById]
GO

/****** Object:  Stored Procedure dbo.spo_OutBill_GetList    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutBill_GetList]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutBill_GetList]
GO

/****** Object:  Stored Procedure dbo.spo_OutBill_GetByPaging    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutBill_GetByPaging]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutBill_GetByPaging]
GO

/****** Object:  Stored Procedure dbo.spo_OutBill_Insert    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutBill_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutBill_Insert]
GO

/****** Object:  Stored Procedure dbo.spo_OutBill_Update    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutBill_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutBill_Update]
GO



SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Delete OutBill by BillId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutBill_Delete
	@BillId int
AS

DELETE FROM [OutBill]
WHERE
	[BillId] = @BillId
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get OutBill by BillId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutBill_GetById
	@BillId int
AS

SELECT
	[BillId]
	, [BillName]
	, [BillEmail]
	, [BillAddress]
	, [BillPhone]
	, [BillDesc]
	, [BillDate]
	, [BillTotal]
	, [BillStatus]
	, [CusId]
FROM
	[OutBill]
WHERE
	[BillId] = @BillId

GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get all from OutBill
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutBill_GetList
AS

SELECT
	[BillId]
	, [BillName]
	, [BillEmail]
	, [BillAddress]
	, [BillPhone]
	, [BillDesc]
	, [BillDate]
	, [BillTotal]
	, [BillStatus]
	, [CusId]
FROM
	[OutBill]

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get OutBill by paging
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[spo_OutBill_GetByPaging]
@PageIndex INT,
@PageSize INT,
@TotalRecord INT OUTPUT
AS
	SELECT @TotalRecord = COUNT(*) FROM [OutBill]
	DECLARE @StartRow INT
	SET @StartRow = (@PageIndex - 1) * @PageSize + 1
	DECLARE @EndRow INT
	SET @EndRow = @PageIndex * @PageSize
SELECT * FROM
(
	SELECT TOP(@EndRow)
	[BillId]
	, [BillName]
	, [BillEmail]
	, [BillAddress]
	, [BillPhone]
	, [BillDesc]
	, [BillDate]
	, [BillTotal]
	, [BillStatus]
	, [CusId]
	, ROW_NUMBER() OVER(ORDER BY BillId ASC) RowIndex
FROM
	[OutBill]
) indexTable
WHERE RowIndex BETWEEN @StartRow AND @EndRow
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Insert into OutBill
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutBill_Insert
	@BillName nvarchar(200), 
	@BillEmail nvarchar(50), 
	@BillAddress nvarchar(100), 
	@BillPhone nvarchar(20), 
	@BillDesc nvarchar(500), 
	@BillDate datetime, 
	@BillTotal float, 
	@BillStatus int, 
	@CusId int, 
	@BillId int OUTPUT
AS
BEGIN

INSERT INTO [OutBill] (
	[BillName]
	, [BillEmail]
	, [BillAddress]
	, [BillPhone]
	, [BillDesc]
	, [BillDate]
	, [BillTotal]
	, [BillStatus]
	, [CusId]
) VALUES (
	@BillName
	, @BillEmail
	, @BillAddress
	, @BillPhone
	, @BillDesc
	, @BillDate
	, @BillTotal
	, @BillStatus
	, @CusId
)

SET @BillId = @@IDENTITY

END


GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Update from OutBill by BillId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutBill_Update
	
	@BillId int 
	, @BillName nvarchar(200) 
	, @BillEmail nvarchar(50) 
	, @BillAddress nvarchar(100) 
	, @BillPhone nvarchar(20) 
	, @BillDesc nvarchar(500) 
	, @BillDate datetime 
	, @BillTotal float 
	, @BillStatus int 
	, @CusId int 
AS

UPDATE [OutBill] SET
	[BillName] = @BillName
	, [BillEmail] = @BillEmail
	, [BillAddress] = @BillAddress
	, [BillPhone] = @BillPhone
	, [BillDesc] = @BillDesc
	, [BillDate] = @BillDate
	, [BillTotal] = @BillTotal
	, [BillStatus] = @BillStatus
	, [CusId] = @CusId
WHERE
	[BillId] = @BillId

GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
/****** Object:  Stored Procedure dbo.spo_OutBillDetail_Delete    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutBillDetail_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutBillDetail_Delete]
GO

/****** Object:  Stored Procedure dbo.spo_OutBillDetail_GetById    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutBillDetail_GetById]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutBillDetail_GetById]
GO

/****** Object:  Stored Procedure dbo.spo_OutBillDetail_GetList    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutBillDetail_GetList]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutBillDetail_GetList]
GO

/****** Object:  Stored Procedure dbo.spo_OutBillDetail_GetByPaging    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutBillDetail_GetByPaging]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutBillDetail_GetByPaging]
GO

/****** Object:  Stored Procedure dbo.spo_OutBillDetail_Insert    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutBillDetail_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutBillDetail_Insert]
GO

/****** Object:  Stored Procedure dbo.spo_OutBillDetail_Update    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutBillDetail_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutBillDetail_Update]
GO



SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Delete OutBillDetail by BillDetailID
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutBillDetail_Delete
	@BillDetailID int
AS

DELETE FROM [OutBillDetail]
WHERE
	[BillDetailID] = @BillDetailID
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get OutBillDetail by BillDetailID
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutBillDetail_GetById
	@BillDetailID int
AS

SELECT
	[BillDetailID]
	, [BillID]
	, [ProID]
	, [BillDetailCnt]
FROM
	[OutBillDetail]
WHERE
	[BillDetailID] = @BillDetailID

GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get all from OutBillDetail
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutBillDetail_GetList
AS

SELECT
	[BillDetailID]
	, [BillID]
	, [ProID]
	, [BillDetailCnt]
FROM
	[OutBillDetail]

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get OutBillDetail by paging
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[spo_OutBillDetail_GetByPaging]
@PageIndex INT,
@PageSize INT,
@TotalRecord INT OUTPUT
AS
	SELECT @TotalRecord = COUNT(*) FROM [OutBillDetail]
	DECLARE @StartRow INT
	SET @StartRow = (@PageIndex - 1) * @PageSize + 1
	DECLARE @EndRow INT
	SET @EndRow = @PageIndex * @PageSize
SELECT * FROM
(
	SELECT TOP(@EndRow)
	[BillDetailID]
	, [BillID]
	, [ProID]
	, [BillDetailCnt]
	, ROW_NUMBER() OVER(ORDER BY BillDetailID ASC) RowIndex
FROM
	[OutBillDetail]
) indexTable
WHERE RowIndex BETWEEN @StartRow AND @EndRow
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Insert into OutBillDetail
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutBillDetail_Insert
	@BillID int, 
	@ProID int, 
	@BillDetailCnt int, 
	@BillDetailID int OUTPUT
AS
BEGIN

INSERT INTO [OutBillDetail] (
	[BillID]
	, [ProID]
	, [BillDetailCnt]
) VALUES (
	@BillID
	, @ProID
	, @BillDetailCnt
)

SET @BillDetailID = @@IDENTITY

END


GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Update from OutBillDetail by BillDetailID
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutBillDetail_Update
	
	@BillDetailID int 
	, @BillID int 
	, @ProID int 
	, @BillDetailCnt int 
AS

UPDATE [OutBillDetail] SET
	[BillID] = @BillID
	, [ProID] = @ProID
	, [BillDetailCnt] = @BillDetailCnt
WHERE
	[BillDetailID] = @BillDetailID

GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
/****** Object:  Stored Procedure dbo.spo_OutBox_Delete    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutBox_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutBox_Delete]
GO

/****** Object:  Stored Procedure dbo.spo_OutBox_GetById    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutBox_GetById]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutBox_GetById]
GO

/****** Object:  Stored Procedure dbo.spo_OutBox_GetList    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutBox_GetList]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutBox_GetList]
GO

/****** Object:  Stored Procedure dbo.spo_OutBox_GetByPaging    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutBox_GetByPaging]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutBox_GetByPaging]
GO

/****** Object:  Stored Procedure dbo.spo_OutBox_Insert    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutBox_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutBox_Insert]
GO

/****** Object:  Stored Procedure dbo.spo_OutBox_Update    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutBox_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutBox_Update]
GO



SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Delete OutBox by BoxId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutBox_Delete
	@BoxId int
AS

DELETE FROM [OutBox]
WHERE
	[BoxId] = @BoxId
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get OutBox by BoxId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutBox_GetById
	@BoxId int
AS

SELECT
	[BoxId]
	, [ItemId]
	, [BoxOrder]
	, [BoxCategory]
	, [BoxImage]
	, [BoxType]
FROM
	[OutBox]
WHERE
	[BoxId] = @BoxId

GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get all from OutBox
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutBox_GetList
AS

SELECT
	[BoxId]
	, [ItemId]
	, [BoxOrder]
	, [BoxCategory]
	, [BoxImage]
	, [BoxType]
FROM
	[OutBox]

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get OutBox by paging
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[spo_OutBox_GetByPaging]
@PageIndex INT,
@PageSize INT,
@TotalRecord INT OUTPUT
AS
	SELECT @TotalRecord = COUNT(*) FROM [OutBox]
	DECLARE @StartRow INT
	SET @StartRow = (@PageIndex - 1) * @PageSize + 1
	DECLARE @EndRow INT
	SET @EndRow = @PageIndex * @PageSize
SELECT * FROM
(
	SELECT TOP(@EndRow)
	[BoxId]
	, [ItemId]
	, [BoxOrder]
	, [BoxCategory]
	, [BoxImage]
	, [BoxType]
	, ROW_NUMBER() OVER(ORDER BY BoxId ASC) RowIndex
FROM
	[OutBox]
) indexTable
WHERE RowIndex BETWEEN @StartRow AND @EndRow
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Insert into OutBox
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutBox_Insert
	@ItemId int, 
	@BoxOrder int, 
	@BoxCategory int, 
	@BoxImage nvarchar(200), 
	@BoxType int, 
	@BoxId int OUTPUT
AS
BEGIN

INSERT INTO [OutBox] (
	[ItemId]
	, [BoxOrder]
	, [BoxCategory]
	, [BoxImage]
	, [BoxType]
) VALUES (
	@ItemId
	, @BoxOrder
	, @BoxCategory
	, @BoxImage
	, @BoxType
)

SET @BoxId = @@IDENTITY

END


GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Update from OutBox by BoxId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutBox_Update
	
	@BoxId int 
	, @ItemId int 
	, @BoxOrder int 
	, @BoxCategory int 
	, @BoxImage nvarchar(200) 
	, @BoxType int 
AS

UPDATE [OutBox] SET
	[ItemId] = @ItemId
	, [BoxOrder] = @BoxOrder
	, [BoxCategory] = @BoxCategory
	, [BoxImage] = @BoxImage
	, [BoxType] = @BoxType
WHERE
	[BoxId] = @BoxId

GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
/****** Object:  Stored Procedure dbo.spo_OutContactUs_Delete    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutContactUs_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutContactUs_Delete]
GO

/****** Object:  Stored Procedure dbo.spo_OutContactUs_GetById    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutContactUs_GetById]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutContactUs_GetById]
GO

/****** Object:  Stored Procedure dbo.spo_OutContactUs_GetList    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutContactUs_GetList]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutContactUs_GetList]
GO

/****** Object:  Stored Procedure dbo.spo_OutContactUs_GetByPaging    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutContactUs_GetByPaging]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutContactUs_GetByPaging]
GO

/****** Object:  Stored Procedure dbo.spo_OutContactUs_Insert    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutContactUs_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutContactUs_Insert]
GO

/****** Object:  Stored Procedure dbo.spo_OutContactUs_Update    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutContactUs_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutContactUs_Update]
GO



SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Delete OutContactUs by ContactId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutContactUs_Delete
	@ContactId int
AS

DELETE FROM [OutContactUs]
WHERE
	[ContactId] = @ContactId
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get OutContactUs by ContactId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutContactUs_GetById
	@ContactId int
AS

SELECT
	[ContactId]
	, [ContactName]
	, [ContactMail]
	, [ContactContent]
	, [ContactStt]
	, [ContactDate]
FROM
	[OutContactUs]
WHERE
	[ContactId] = @ContactId

GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get all from OutContactUs
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutContactUs_GetList
AS

SELECT
	[ContactId]
	, [ContactName]
	, [ContactMail]
	, [ContactContent]
	, [ContactStt]
	, [ContactDate]
FROM
	[OutContactUs]

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get OutContactUs by paging
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[spo_OutContactUs_GetByPaging]
@PageIndex INT,
@PageSize INT,
@TotalRecord INT OUTPUT
AS
	SELECT @TotalRecord = COUNT(*) FROM [OutContactUs]
	DECLARE @StartRow INT
	SET @StartRow = (@PageIndex - 1) * @PageSize + 1
	DECLARE @EndRow INT
	SET @EndRow = @PageIndex * @PageSize
SELECT * FROM
(
	SELECT TOP(@EndRow)
	[ContactId]
	, [ContactName]
	, [ContactMail]
	, [ContactContent]
	, [ContactStt]
	, [ContactDate]
	, ROW_NUMBER() OVER(ORDER BY ContactId ASC) RowIndex
FROM
	[OutContactUs]
) indexTable
WHERE RowIndex BETWEEN @StartRow AND @EndRow
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Insert into OutContactUs
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutContactUs_Insert
	@ContactName nvarchar(100), 
	@ContactMail nvarchar(50), 
	@ContactContent nvarchar(MAX), 
	@ContactStt int, 
	@ContactDate datetime, 
	@ContactId int OUTPUT
AS
BEGIN

INSERT INTO [OutContactUs] (
	[ContactName]
	, [ContactMail]
	, [ContactContent]
	, [ContactStt]
	, [ContactDate]
) VALUES (
	@ContactName
	, @ContactMail
	, @ContactContent
	, @ContactStt
	, @ContactDate
)

SET @ContactId = @@IDENTITY

END


GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Update from OutContactUs by ContactId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutContactUs_Update
	
	@ContactId int 
	, @ContactName nvarchar(100) 
	, @ContactMail nvarchar(50) 
	, @ContactContent nvarchar(MAX) 
	, @ContactStt int 
	, @ContactDate datetime 
AS

UPDATE [OutContactUs] SET
	[ContactName] = @ContactName
	, [ContactMail] = @ContactMail
	, [ContactContent] = @ContactContent
	, [ContactStt] = @ContactStt
	, [ContactDate] = @ContactDate
WHERE
	[ContactId] = @ContactId

GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
/****** Object:  Stored Procedure dbo.spo_OutCustomer_Delete    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutCustomer_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutCustomer_Delete]
GO

/****** Object:  Stored Procedure dbo.spo_OutCustomer_GetById    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutCustomer_GetById]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutCustomer_GetById]
GO

/****** Object:  Stored Procedure dbo.spo_OutCustomer_GetList    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutCustomer_GetList]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutCustomer_GetList]
GO

/****** Object:  Stored Procedure dbo.spo_OutCustomer_GetByPaging    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutCustomer_GetByPaging]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutCustomer_GetByPaging]
GO

/****** Object:  Stored Procedure dbo.spo_OutCustomer_Insert    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutCustomer_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutCustomer_Insert]
GO

/****** Object:  Stored Procedure dbo.spo_OutCustomer_Update    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutCustomer_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutCustomer_Update]
GO



SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Delete OutCustomer by CusId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutCustomer_Delete
	@CusId int
AS

DELETE FROM [OutCustomer]
WHERE
	[CusId] = @CusId
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get OutCustomer by CusId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutCustomer_GetById
	@CusId int
AS

SELECT
	[CusId]
	, [CusUserName]
	, [CusPass]
	, [CusEmail]
	, [CusPhone]
	, [CusFullName]
	, [CusAddress]
	, [CusImg]
	, [CusIdCard]
	, [CusStatus]
FROM
	[OutCustomer]
WHERE
	[CusId] = @CusId

GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get all from OutCustomer
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutCustomer_GetList
AS

SELECT
	[CusId]
	, [CusUserName]
	, [CusPass]
	, [CusEmail]
	, [CusPhone]
	, [CusFullName]
	, [CusAddress]
	, [CusImg]
	, [CusIdCard]
	, [CusStatus]
FROM
	[OutCustomer]

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get OutCustomer by paging
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[spo_OutCustomer_GetByPaging]
@PageIndex INT,
@PageSize INT,
@TotalRecord INT OUTPUT
AS
	SELECT @TotalRecord = COUNT(*) FROM [OutCustomer]
	DECLARE @StartRow INT
	SET @StartRow = (@PageIndex - 1) * @PageSize + 1
	DECLARE @EndRow INT
	SET @EndRow = @PageIndex * @PageSize
SELECT * FROM
(
	SELECT TOP(@EndRow)
	[CusId]
	, [CusUserName]
	, [CusPass]
	, [CusEmail]
	, [CusPhone]
	, [CusFullName]
	, [CusAddress]
	, [CusImg]
	, [CusIdCard]
	, [CusStatus]
	, ROW_NUMBER() OVER(ORDER BY CusId ASC) RowIndex
FROM
	[OutCustomer]
) indexTable
WHERE RowIndex BETWEEN @StartRow AND @EndRow
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Insert into OutCustomer
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutCustomer_Insert
	@CusUserName nvarchar(30), 
	@CusPass nvarchar(30), 
	@CusEmail nvarchar(40), 
	@CusPhone nvarchar(15), 
	@CusFullName nvarchar(200), 
	@CusAddress nvarchar(300), 
	@CusImg nvarchar(500), 
	@CusIdCard nvarchar(20), 
	@CusStatus int, 
	@CusId int OUTPUT
AS
BEGIN

INSERT INTO [OutCustomer] (
	[CusUserName]
	, [CusPass]
	, [CusEmail]
	, [CusPhone]
	, [CusFullName]
	, [CusAddress]
	, [CusImg]
	, [CusIdCard]
	, [CusStatus]
) VALUES (
	@CusUserName
	, @CusPass
	, @CusEmail
	, @CusPhone
	, @CusFullName
	, @CusAddress
	, @CusImg
	, @CusIdCard
	, @CusStatus
)

SET @CusId = @@IDENTITY

END


GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Update from OutCustomer by CusId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutCustomer_Update
	
	@CusId int 
	, @CusUserName nvarchar(30) 
	, @CusPass nvarchar(30) 
	, @CusEmail nvarchar(40) 
	, @CusPhone nvarchar(15) 
	, @CusFullName nvarchar(200) 
	, @CusAddress nvarchar(300) 
	, @CusImg nvarchar(500) 
	, @CusIdCard nvarchar(20) 
	, @CusStatus int 
AS

UPDATE [OutCustomer] SET
	[CusUserName] = @CusUserName
	, [CusPass] = @CusPass
	, [CusEmail] = @CusEmail
	, [CusPhone] = @CusPhone
	, [CusFullName] = @CusFullName
	, [CusAddress] = @CusAddress
	, [CusImg] = @CusImg
	, [CusIdCard] = @CusIdCard
	, [CusStatus] = @CusStatus
WHERE
	[CusId] = @CusId

GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
/****** Object:  Stored Procedure dbo.spo_OutGallery_Delete    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutGallery_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutGallery_Delete]
GO

/****** Object:  Stored Procedure dbo.spo_OutGallery_GetById    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutGallery_GetById]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutGallery_GetById]
GO

/****** Object:  Stored Procedure dbo.spo_OutGallery_GetList    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutGallery_GetList]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutGallery_GetList]
GO

/****** Object:  Stored Procedure dbo.spo_OutGallery_GetByPaging    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutGallery_GetByPaging]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutGallery_GetByPaging]
GO

/****** Object:  Stored Procedure dbo.spo_OutGallery_Insert    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutGallery_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutGallery_Insert]
GO

/****** Object:  Stored Procedure dbo.spo_OutGallery_Update    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutGallery_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutGallery_Update]
GO



SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Delete OutGallery by GalleryId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutGallery_Delete
	@GalleryId int
AS

DELETE FROM [OutGallery]
WHERE
	[GalleryId] = @GalleryId
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get OutGallery by GalleryId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutGallery_GetById
	@GalleryId int
AS

SELECT
	[GalleryId]
	, [ProId]
	, [GalleryImg]
	, [GalleryThumb]
	, [GalleryDate]
FROM
	[OutGallery]
WHERE
	[GalleryId] = @GalleryId

GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get all from OutGallery
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutGallery_GetList
AS

SELECT
	[GalleryId]
	, [ProId]
	, [GalleryImg]
	, [GalleryThumb]
	, [GalleryDate]
FROM
	[OutGallery]

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get OutGallery by paging
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[spo_OutGallery_GetByPaging]
@PageIndex INT,
@PageSize INT,
@TotalRecord INT OUTPUT
AS
	SELECT @TotalRecord = COUNT(*) FROM [OutGallery]
	DECLARE @StartRow INT
	SET @StartRow = (@PageIndex - 1) * @PageSize + 1
	DECLARE @EndRow INT
	SET @EndRow = @PageIndex * @PageSize
SELECT * FROM
(
	SELECT TOP(@EndRow)
	[GalleryId]
	, [ProId]
	, [GalleryImg]
	, [GalleryThumb]
	, [GalleryDate]
	, ROW_NUMBER() OVER(ORDER BY GalleryId ASC) RowIndex
FROM
	[OutGallery]
) indexTable
WHERE RowIndex BETWEEN @StartRow AND @EndRow
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Insert into OutGallery
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutGallery_Insert
	@ProId int, 
	@GalleryImg nvarchar(500), 
	@GalleryThumb nvarchar(500), 
	@GalleryDate datetime, 
	@GalleryId int OUTPUT
AS
BEGIN

INSERT INTO [OutGallery] (
	[ProId]
	, [GalleryImg]
	, [GalleryThumb]
	, [GalleryDate]
) VALUES (
	@ProId
	, @GalleryImg
	, @GalleryThumb
	, @GalleryDate
)

SET @GalleryId = @@IDENTITY

END


GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Update from OutGallery by GalleryId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutGallery_Update
	
	@GalleryId int 
	, @ProId int 
	, @GalleryImg nvarchar(500) 
	, @GalleryThumb nvarchar(500) 
	, @GalleryDate datetime 
AS

UPDATE [OutGallery] SET
	[ProId] = @ProId
	, [GalleryImg] = @GalleryImg
	, [GalleryThumb] = @GalleryThumb
	, [GalleryDate] = @GalleryDate
WHERE
	[GalleryId] = @GalleryId

GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
/****** Object:  Stored Procedure dbo.spo_OutNew_Delete    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutNew_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutNew_Delete]
GO

/****** Object:  Stored Procedure dbo.spo_OutNew_GetById    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutNew_GetById]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutNew_GetById]
GO

/****** Object:  Stored Procedure dbo.spo_OutNew_GetList    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutNew_GetList]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutNew_GetList]
GO

/****** Object:  Stored Procedure dbo.spo_OutNew_GetByPaging    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutNew_GetByPaging]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutNew_GetByPaging]
GO

/****** Object:  Stored Procedure dbo.spo_OutNew_Insert    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutNew_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutNew_Insert]
GO

/****** Object:  Stored Procedure dbo.spo_OutNew_Update    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutNew_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutNew_Update]
GO



SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Delete OutNew by NewId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutNew_Delete
	@NewId int
AS

DELETE FROM [OutNew]
WHERE
	[NewId] = @NewId
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get OutNew by NewId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutNew_GetById
	@NewId int
AS

SELECT
	[NewId]
	, [CatId]
	, [NewAuthor]
	, [NewTitle]
	, [NewDesc]
	, [NewDetail]
	, [NewImage]
	, [NewImage2]
	, [NewImage3]
	, [NewStatus]
	, [NewPublishDate]
	, [NewModifiedDate]
	, [UserId]
FROM
	[OutNew]
WHERE
	[NewId] = @NewId

GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get all from OutNew
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutNew_GetList
AS

SELECT
	[NewId]
	, [CatId]
	, [NewAuthor]
	, [NewTitle]
	, [NewDesc]
	, [NewDetail]
	, [NewImage]
	, [NewImage2]
	, [NewImage3]
	, [NewStatus]
	, [NewPublishDate]
	, [NewModifiedDate]
	, [UserId]
FROM
	[OutNew]

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get OutNew by paging
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[spo_OutNew_GetByPaging]
@PageIndex INT,
@PageSize INT,
@TotalRecord INT OUTPUT
AS
	SELECT @TotalRecord = COUNT(*) FROM [OutNew]
	DECLARE @StartRow INT
	SET @StartRow = (@PageIndex - 1) * @PageSize + 1
	DECLARE @EndRow INT
	SET @EndRow = @PageIndex * @PageSize
SELECT * FROM
(
	SELECT TOP(@EndRow)
	[NewId]
	, [CatId]
	, [NewAuthor]
	, [NewTitle]
	, [NewDesc]
	, [NewDetail]
	, [NewImage]
	, [NewImage2]
	, [NewImage3]
	, [NewStatus]
	, [NewPublishDate]
	, [NewModifiedDate]
	, [UserId]
	, ROW_NUMBER() OVER(ORDER BY NewId ASC) RowIndex
FROM
	[OutNew]
) indexTable
WHERE RowIndex BETWEEN @StartRow AND @EndRow
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Insert into OutNew
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutNew_Insert
	@CatId int, 
	@NewAuthor nvarchar(100), 
	@NewTitle nvarchar(200), 
	@NewDesc nvarchar(500), 
	@NewDetail nvarchar(MAX), 
	@NewImage nvarchar(200), 
	@NewImage2 nvarchar(200), 
	@NewImage3 nvarchar(200), 
	@NewStatus int, 
	@NewPublishDate datetime, 
	@NewModifiedDate datetime, 
	@UserId int, 
	@NewId int OUTPUT
AS
BEGIN

INSERT INTO [OutNew] (
	[CatId]
	, [NewAuthor]
	, [NewTitle]
	, [NewDesc]
	, [NewDetail]
	, [NewImage]
	, [NewImage2]
	, [NewImage3]
	, [NewStatus]
	, [NewPublishDate]
	, [NewModifiedDate]
	, [UserId]
) VALUES (
	@CatId
	, @NewAuthor
	, @NewTitle
	, @NewDesc
	, @NewDetail
	, @NewImage
	, @NewImage2
	, @NewImage3
	, @NewStatus
	, @NewPublishDate
	, @NewModifiedDate
	, @UserId
)

SET @NewId = @@IDENTITY

END


GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Update from OutNew by NewId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutNew_Update
	
	@NewId int 
	, @CatId int 
	, @NewAuthor nvarchar(100) 
	, @NewTitle nvarchar(200) 
	, @NewDesc nvarchar(500) 
	, @NewDetail nvarchar(MAX) 
	, @NewImage nvarchar(200) 
	, @NewImage2 nvarchar(200) 
	, @NewImage3 nvarchar(200) 
	, @NewStatus int 
	, @NewPublishDate datetime 
	, @NewModifiedDate datetime 
	, @UserId int 
AS

UPDATE [OutNew] SET
	[CatId] = @CatId
	, [NewAuthor] = @NewAuthor
	, [NewTitle] = @NewTitle
	, [NewDesc] = @NewDesc
	, [NewDetail] = @NewDetail
	, [NewImage] = @NewImage
	, [NewImage2] = @NewImage2
	, [NewImage3] = @NewImage3
	, [NewStatus] = @NewStatus
	, [NewPublishDate] = @NewPublishDate
	, [NewModifiedDate] = @NewModifiedDate
	, [UserId] = @UserId
WHERE
	[NewId] = @NewId

GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
/****** Object:  Stored Procedure dbo.spo_OutProduct_Delete    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutProduct_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutProduct_Delete]
GO

/****** Object:  Stored Procedure dbo.spo_OutProduct_GetById    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutProduct_GetById]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutProduct_GetById]
GO

/****** Object:  Stored Procedure dbo.spo_OutProduct_GetList    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutProduct_GetList]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutProduct_GetList]
GO

/****** Object:  Stored Procedure dbo.spo_OutProduct_GetByPaging    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutProduct_GetByPaging]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutProduct_GetByPaging]
GO

/****** Object:  Stored Procedure dbo.spo_OutProduct_Insert    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutProduct_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutProduct_Insert]
GO

/****** Object:  Stored Procedure dbo.spo_OutProduct_Update    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutProduct_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutProduct_Update]
GO



SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Delete OutProduct by ProId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutProduct_Delete
	@ProId int
AS

DELETE FROM [OutProduct]
WHERE
	[ProId] = @ProId
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get OutProduct by ProId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutProduct_GetById
	@ProId int
AS

SELECT
	[ProId]
	, [CatId]
	, [ProName]
	, [ProCode]
	, [ProDesc]
	, [ProDetail1]
	, [ProDetail2]
	, [ProDetail3]
	, [ProImage1]
	, [ProImage2]
	, [ProImage3]
	, [ProImage4]
	, [ProCreatedDate]
	, [ProPublishDate]
	, [ProOldPrice]
	, [ProNewPrice]
	, [ProHot]
	, [ProNew]
	, [ProStatus]
	, [ProIsStock]
	, [ProPromotion]
FROM
	[OutProduct]
WHERE
	[ProId] = @ProId

GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get all from OutProduct
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutProduct_GetList
AS

SELECT
	[ProId]
	, [CatId]
	, [ProName]
	, [ProCode]
	, [ProDesc]
	, [ProDetail1]
	, [ProDetail2]
	, [ProDetail3]
	, [ProImage1]
	, [ProImage2]
	, [ProImage3]
	, [ProImage4]
	, [ProCreatedDate]
	, [ProPublishDate]
	, [ProOldPrice]
	, [ProNewPrice]
	, [ProHot]
	, [ProNew]
	, [ProStatus]
	, [ProIsStock]
	, [ProPromotion]
FROM
	[OutProduct]

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get OutProduct by paging
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[spo_OutProduct_GetByPaging]
@PageIndex INT,
@PageSize INT,
@TotalRecord INT OUTPUT
AS
	SELECT @TotalRecord = COUNT(*) FROM [OutProduct]
	DECLARE @StartRow INT
	SET @StartRow = (@PageIndex - 1) * @PageSize + 1
	DECLARE @EndRow INT
	SET @EndRow = @PageIndex * @PageSize
SELECT * FROM
(
	SELECT TOP(@EndRow)
	[ProId]
	, [CatId]
	, [ProName]
	, [ProCode]
	, [ProDesc]
	, [ProDetail1]
	, [ProDetail2]
	, [ProDetail3]
	, [ProImage1]
	, [ProImage2]
	, [ProImage3]
	, [ProImage4]
	, [ProCreatedDate]
	, [ProPublishDate]
	, [ProOldPrice]
	, [ProNewPrice]
	, [ProHot]
	, [ProNew]
	, [ProStatus]
	, [ProIsStock]
	, [ProPromotion]
	, ROW_NUMBER() OVER(ORDER BY ProId ASC) RowIndex
FROM
	[OutProduct]
) indexTable
WHERE RowIndex BETWEEN @StartRow AND @EndRow
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Insert into OutProduct
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutProduct_Insert
	@CatId int, 
	@ProName nvarchar(300), 
	@ProCode nvarchar(20), 
	@ProDesc nvarchar(500), 
	@ProDetail1 nvarchar(MAX), 
	@ProDetail2 nvarchar(MAX), 
	@ProDetail3 nvarchar(MAX), 
	@ProImage1 nvarchar(100), 
	@ProImage2 nvarchar(100), 
	@ProImage3 nvarchar(100), 
	@ProImage4 nvarchar(100), 
	@ProCreatedDate datetime, 
	@ProPublishDate datetime, 
	@ProOldPrice float, 
	@ProNewPrice float, 
	@ProHot tinyint, 
	@ProNew tinyint, 
	@ProStatus tinyint, 
	@ProIsStock tinyint, 
	@ProPromotion nvarchar(500), 
	@ProId int OUTPUT
AS
BEGIN

INSERT INTO [OutProduct] (
	[CatId]
	, [ProName]
	, [ProCode]
	, [ProDesc]
	, [ProDetail1]
	, [ProDetail2]
	, [ProDetail3]
	, [ProImage1]
	, [ProImage2]
	, [ProImage3]
	, [ProImage4]
	, [ProCreatedDate]
	, [ProPublishDate]
	, [ProOldPrice]
	, [ProNewPrice]
	, [ProHot]
	, [ProNew]
	, [ProStatus]
	, [ProIsStock]
	, [ProPromotion]
) VALUES (
	@CatId
	, @ProName
	, @ProCode
	, @ProDesc
	, @ProDetail1
	, @ProDetail2
	, @ProDetail3
	, @ProImage1
	, @ProImage2
	, @ProImage3
	, @ProImage4
	, @ProCreatedDate
	, @ProPublishDate
	, @ProOldPrice
	, @ProNewPrice
	, @ProHot
	, @ProNew
	, @ProStatus
	, @ProIsStock
	, @ProPromotion
)

SET @ProId = @@IDENTITY

END


GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Update from OutProduct by ProId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutProduct_Update
	
	@ProId int 
	, @CatId int 
	, @ProName nvarchar(300) 
	, @ProCode nvarchar(20) 
	, @ProDesc nvarchar(500) 
	, @ProDetail1 nvarchar(MAX) 
	, @ProDetail2 nvarchar(MAX) 
	, @ProDetail3 nvarchar(MAX) 
	, @ProImage1 nvarchar(100) 
	, @ProImage2 nvarchar(100) 
	, @ProImage3 nvarchar(100) 
	, @ProImage4 nvarchar(100) 
	, @ProCreatedDate datetime 
	, @ProPublishDate datetime 
	, @ProOldPrice float 
	, @ProNewPrice float 
	, @ProHot tinyint 
	, @ProNew tinyint 
	, @ProStatus tinyint 
	, @ProIsStock tinyint 
	, @ProPromotion nvarchar(500) 
AS

UPDATE [OutProduct] SET
	[CatId] = @CatId
	, [ProName] = @ProName
	, [ProCode] = @ProCode
	, [ProDesc] = @ProDesc
	, [ProDetail1] = @ProDetail1
	, [ProDetail2] = @ProDetail2
	, [ProDetail3] = @ProDetail3
	, [ProImage1] = @ProImage1
	, [ProImage2] = @ProImage2
	, [ProImage3] = @ProImage3
	, [ProImage4] = @ProImage4
	, [ProCreatedDate] = @ProCreatedDate
	, [ProPublishDate] = @ProPublishDate
	, [ProOldPrice] = @ProOldPrice
	, [ProNewPrice] = @ProNewPrice
	, [ProHot] = @ProHot
	, [ProNew] = @ProNew
	, [ProStatus] = @ProStatus
	, [ProIsStock] = @ProIsStock
	, [ProPromotion] = @ProPromotion
WHERE
	[ProId] = @ProId

GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
/****** Object:  Stored Procedure dbo.spo_OutCategory_Delete    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutCategory_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutCategory_Delete]
GO

/****** Object:  Stored Procedure dbo.spo_OutCategory_GetById    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutCategory_GetById]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutCategory_GetById]
GO

/****** Object:  Stored Procedure dbo.spo_OutCategory_GetList    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutCategory_GetList]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutCategory_GetList]
GO

/****** Object:  Stored Procedure dbo.spo_OutCategory_GetByPaging    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutCategory_GetByPaging]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutCategory_GetByPaging]
GO

/****** Object:  Stored Procedure dbo.spo_OutCategory_Insert    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutCategory_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutCategory_Insert]
GO

/****** Object:  Stored Procedure dbo.spo_OutCategory_Update    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spo_OutCategory_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spo_OutCategory_Update]
GO



SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Delete OutCategory by CatId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutCategory_Delete
	@CatId int
AS

DELETE FROM [OutCategory]
WHERE
	[CatId] = @CatId
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get OutCategory by CatId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutCategory_GetById
	@CatId int
AS

SELECT
	[CatId]
	, [CatParentId]
	, [CatName]
	, [CatStatus]
	, [CatOrder]
	, [CatType]
FROM
	[OutCategory]
WHERE
	[CatId] = @CatId

GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get all from OutCategory
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutCategory_GetList
AS

SELECT
	[CatId]
	, [CatParentId]
	, [CatName]
	, [CatStatus]
	, [CatOrder]
	, [CatType]
FROM
	[OutCategory]

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get OutCategory by paging
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[spo_OutCategory_GetByPaging]
@PageIndex INT,
@PageSize INT,
@TotalRecord INT OUTPUT
AS
	SELECT @TotalRecord = COUNT(*) FROM [OutCategory]
	DECLARE @StartRow INT
	SET @StartRow = (@PageIndex - 1) * @PageSize + 1
	DECLARE @EndRow INT
	SET @EndRow = @PageIndex * @PageSize
SELECT * FROM
(
	SELECT TOP(@EndRow)
	[CatId]
	, [CatParentId]
	, [CatName]
	, [CatStatus]
	, [CatOrder]
	, [CatType]
	, ROW_NUMBER() OVER(ORDER BY CatId ASC) RowIndex
FROM
	[OutCategory]
) indexTable
WHERE RowIndex BETWEEN @StartRow AND @EndRow
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Insert into OutCategory
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutCategory_Insert
	@CatParentId int, 
	@CatName nvarchar(50), 
	@CatStatus int, 
	@CatOrder int, 
	@CatType int, 
	@CatId int OUTPUT
AS
BEGIN

INSERT INTO [OutCategory] (
	[CatParentId]
	, [CatName]
	, [CatStatus]
	, [CatOrder]
	, [CatType]
) VALUES (
	@CatParentId
	, @CatName
	, @CatStatus
	, @CatOrder
	, @CatType
)

SET @CatId = @@IDENTITY

END


GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Update from OutCategory by CatId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spo_OutCategory_Update
	
	@CatId int 
	, @CatParentId int 
	, @CatName nvarchar(50) 
	, @CatStatus int 
	, @CatOrder int 
	, @CatType int 
AS

UPDATE [OutCategory] SET
	[CatParentId] = @CatParentId
	, [CatName] = @CatName
	, [CatStatus] = @CatStatus
	, [CatOrder] = @CatOrder
	, [CatType] = @CatType
WHERE
	[CatId] = @CatId

GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
/****** Object:  Stored Procedure dbo.spi_InGroup_Delete    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spi_InGroup_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spi_InGroup_Delete]
GO

/****** Object:  Stored Procedure dbo.spi_InGroup_GetById    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spi_InGroup_GetById]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spi_InGroup_GetById]
GO

/****** Object:  Stored Procedure dbo.spi_InGroup_GetList    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spi_InGroup_GetList]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spi_InGroup_GetList]
GO

/****** Object:  Stored Procedure dbo.spi_InGroup_GetByPaging    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spi_InGroup_GetByPaging]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spi_InGroup_GetByPaging]
GO

/****** Object:  Stored Procedure dbo.spi_InGroup_Insert    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spi_InGroup_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spi_InGroup_Insert]
GO

/****** Object:  Stored Procedure dbo.spi_InGroup_Update    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spi_InGroup_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spi_InGroup_Update]
GO



SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Delete InGroup by GroupId
------------------------------------------------------------------------------------------------------------------------
CREATE PROCEDURE dbo.spi_InGroup_Delete
	@GroupId int
AS

DELETE FROM [InGroup]
WHERE
	[GroupId] = @GroupId
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get InGroup by GroupId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spi_InGroup_GetById
	@GroupId int
AS

SELECT
	[GroupId]
	, [GroupName]
	, [GroupStatus]
FROM
	[InGroup]
WHERE
	[GroupId] = @GroupId

GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get all from InGroup
------------------------------------------------------------------------------------------------------------------------
CREATE PROCEDURE dbo.spi_InGroup_GetList
AS

SELECT
	[GroupId]
	, [GroupName]
	, [GroupStatus]
FROM
	[InGroup]
ORDER BY [GroupId] ASC
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get InGroup by paging
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[spi_InGroup_GetByPaging]
@PageIndex INT,
@PageSize INT,
@TotalRecord INT OUTPUT
AS
	SELECT @TotalRecord = COUNT(*) FROM [InGroup]
	DECLARE @StartRow INT
	SET @StartRow = (@PageIndex - 1) * @PageSize + 1
	DECLARE @EndRow INT
	SET @EndRow = @PageIndex * @PageSize
SELECT * FROM
(
	SELECT TOP(@EndRow)
	[GroupId]
	, [GroupName]
	, [GroupStatus]
	, ROW_NUMBER() OVER(ORDER BY GroupId ASC) RowIndex
FROM
	[InGroup]
) indexTable
WHERE RowIndex BETWEEN @StartRow AND @EndRow
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Insert into InGroup
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spi_InGroup_Insert
	@GroupName nvarchar(100), 
	@GroupStatus int, 
	@GroupId int OUTPUT
AS
BEGIN

INSERT INTO [InGroup] (
	[GroupName]
	, [GroupStatus]
) VALUES (
	@GroupName
	, @GroupStatus
)

SET @GroupId = @@IDENTITY

END


GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Update from InGroup by GroupId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spi_InGroup_Update
	
	@GroupId int 
	, @GroupName nvarchar(100) 
	, @GroupStatus int 
AS

UPDATE [InGroup] SET
	[GroupName] = @GroupName
	, [GroupStatus] = @GroupStatus
WHERE
	[GroupId] = @GroupId

GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
/****** Object:  Stored Procedure dbo.spi_InLog_Delete    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spi_InLog_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spi_InLog_Delete]
GO

/****** Object:  Stored Procedure dbo.spi_InLog_GetById    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spi_InLog_GetById]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spi_InLog_GetById]
GO

/****** Object:  Stored Procedure dbo.spi_InLog_GetList    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spi_InLog_GetList]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spi_InLog_GetList]
GO

/****** Object:  Stored Procedure dbo.spi_InLog_GetByPaging    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spi_InLog_GetByPaging]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spi_InLog_GetByPaging]
GO

/****** Object:  Stored Procedure dbo.spi_InLog_Insert    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spi_InLog_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spi_InLog_Insert]
GO

/****** Object:  Stored Procedure dbo.spi_InLog_Update    Script Date: 2014-05-02 12:01 PM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spi_InLog_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[spi_InLog_Update]
GO



SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Delete InLog by LogId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spi_InLog_Delete
	@LogId int
AS

DELETE FROM [InLog]
WHERE
	[LogId] = @LogId
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get InLog by LogId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spi_InLog_GetById
	@LogId int
AS

SELECT
	[LogId]
	, [UserId]
	, [LogAction]
	, [Field1]
	, [Field2]
	, [Field3]
	, [LogDate]
FROM
	[InLog]
WHERE
	[LogId] = @LogId

GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get all from InLog
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spi_InLog_GetList
AS

SELECT
	[LogId]
	, [UserId]
	, [LogAction]
	, [Field1]
	, [Field2]
	, [Field3]
	, [LogDate]
FROM
	[InLog]

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Get InLog by paging
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[spi_InLog_GetByPaging]
@PageIndex INT,
@PageSize INT,
@TotalRecord INT OUTPUT
AS
	SELECT @TotalRecord = COUNT(*) FROM [InLog]
	DECLARE @StartRow INT
	SET @StartRow = (@PageIndex - 1) * @PageSize + 1
	DECLARE @EndRow INT
	SET @EndRow = @PageIndex * @PageSize
SELECT * FROM
(
	SELECT TOP(@EndRow)
	[LogId]
	, [UserId]
	, [LogAction]
	, [Field1]
	, [Field2]
	, [Field3]
	, [LogDate]
	, ROW_NUMBER() OVER(ORDER BY LogId ASC) RowIndex
FROM
	[InLog]
) indexTable
WHERE RowIndex BETWEEN @StartRow AND @EndRow
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Insert into InLog
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spi_InLog_Insert
	@UserId int, 
	@LogAction int, 
	@Field1 nvarchar(200), 
	@Field2 nvarchar(200), 
	@Field3 nvarchar(200), 
	@LogDate datetime, 
	@LogId int OUTPUT
AS
BEGIN

INSERT INTO [InLog] (
	[UserId]
	, [LogAction]
	, [Field1]
	, [Field2]
	, [Field3]
	, [LogDate]
) VALUES (
	@UserId
	, @LogAction
	, @Field1
	, @Field2
	, @Field3
	, @LogDate
)

SET @LogId = @@IDENTITY

END


GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO
------------------------------------------------------------------------------------------------------------------------
-- Author:       
-- Created Date: 2014-05-02 12:01 PM
-- Description:  Update from InLog by LogId
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE dbo.spi_InLog_Update
	
	@LogId int 
	, @UserId int 
	, @LogAction int 
	, @Field1 nvarchar(200) 
	, @Field2 nvarchar(200) 
	, @Field3 nvarchar(200) 
	, @LogDate datetime 
AS

UPDATE [InLog] SET
	[UserId] = @UserId
	, [LogAction] = @LogAction
	, [Field1] = @Field1
	, [Field2] = @Field2
	, [Field3] = @Field3
	, [LogDate] = @LogDate
WHERE
	[LogId] = @LogId

GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO